package com.ruoyi.insect.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.insect.mapper.CropDiseaseMappingMapper;
import com.ruoyi.insect.domain.CropDiseaseMapping;
import com.ruoyi.insect.service.ICropDiseaseMappingService;

/**
 * 作物病虫害映射Service业务层处理
 */
@Service
public class CropDiseaseMappingServiceImpl implements ICropDiseaseMappingService {
    @Autowired
    private CropDiseaseMappingMapper cropDiseaseMappingMapper;

    /**
     * 查询作物病虫害映射
     */
    @Override
    public CropDiseaseMapping selectCropDiseaseMappingById(Long id) {
        return cropDiseaseMappingMapper.selectCropDiseaseMappingById(id);
    }

    /**
     * 查询作物病虫害映射列表
     */
    @Override
    public List<CropDiseaseMapping> selectCropDiseaseMappingList(CropDiseaseMapping cropDiseaseMapping) {
        return cropDiseaseMappingMapper.selectCropDiseaseMappingList(cropDiseaseMapping);
    }

    /**
     * 新增作物病虫害映射
     */
    @Override
    public int insertCropDiseaseMapping(CropDiseaseMapping cropDiseaseMapping) {
        return cropDiseaseMappingMapper.insertCropDiseaseMapping(cropDiseaseMapping);
    }

    /**
     * 修改作物病虫害映射
     */
    @Override
    public int updateCropDiseaseMapping(CropDiseaseMapping cropDiseaseMapping) {
        return cropDiseaseMappingMapper.updateCropDiseaseMapping(cropDiseaseMapping);
    }

    /**
     * 批量删除作物病虫害映射
     */
    @Override
    public int deleteCropDiseaseMappingByIds(Long[] ids) {
        return cropDiseaseMappingMapper.deleteCropDiseaseMappingByIds(ids);
    }

    /**
     * 删除作物病虫害映射信息
     */
    @Override
    public int deleteCropDiseaseMappingById(Long id) {
        return cropDiseaseMappingMapper.deleteCropDiseaseMappingById(id);
    }

    /**
     * 根据作物名称查询病虫害列表
     */
    @Override
    public List<String> getDiseaseListByCrop(String cropName) {
        return cropDiseaseMappingMapper.selectDiseaseNamesByCrop(cropName);
    }

    /**
     * 获取所有作物名称列表
     */
    @Override
    public List<String> getAllCropNames() {
        return cropDiseaseMappingMapper.selectAllCropNames();
    }

    /**
     * 验证作物和病虫害的映射是否存在
     */
    @Override
    public boolean checkCropDiseaseMapping(String cropName, String diseaseName) {
        int count = cropDiseaseMappingMapper.checkCropDiseaseExists(cropName, diseaseName);
        return count > 0;
    }
}
